﻿<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php include("includes/header.php"); ?>
<?php //check if GET set
	if (!isset($_GET['userid'])) {
		$to = "client.php";
		redirect_to($to);
		exit;  
		};
 ?>

<?php //check if user has primary photo

	$query = "SELECT *";
	$query .= " FROM `foto`";
	$query .= " WHERE `foto`.userid =";
	$query .= "'".$_GET['userid']."'";
	$query .= " AND `pagrindine` = 1";
	//echo $query."</br>";
	$result_set = mysql_query($query, $connection);
	$subject = mysql_fetch_array($result_set);
	
	if (($subject['pagrindine']) !=0) {
	$message = "Pagrindine foto jau yra";
	$pagridine_yra = 1;
	$foto_location = $subject['path'];
	$foto_id = $subject['fotoid'];
	
	} else {
	$message = "Pagrindines foto nera";
	$pagridine_yra = 0;
	};
	
	
?>

 <?php //procesinam ka gaunam is post
 
	if (isset($_POST['tautybe'])) {
		if (($_POST['tautybe']) ==0){
		$to = "problem.php";
		redirect_to ($to);
		};
		if (($_POST['pilietybe']) ==0){
		$to = "problem.php";
		redirect_to ($to);
		};
		
		$pil = ($_POST['pilietybe']);
		$tau = ($_POST['tautybe']);
		
		$sql = "UPDATE `user` SET";
		$sql .= " `pilietybeid` =";
		$sql .= $pil . ", ";
		$sql .= " `tautybeid` =";
		$sql .= $tau . " ";
		$sql .= " WHERE `userid` = ";
		$sql .= ($_GET['userid']);
		$sql .= " LIMIT 1;";
		
		$result = mysql_query($sql, $connection);
			if ($result) {
			
	//===========================================================//
	//   HZ kur redirect
	//===========================================================//
			
			if (($_GET['new'])==1){
				$to = "issilav.php?new=1&userid=" . $_GET['userid'];
			} else { 
				$to = "summary.php?userid=" . $_GET['userid'];
			};	
				redirect_to($to);
				// Success!
				//$message .= "</br>Client updated Successsullyy!! </br>";
			} else {
				// Display error message.
				$message .= "<p>Client update failed.</p>";
				$message .= "<p>" . mysql_error() . "</p>";
			};
		
		
	};
	
  

 ?>

					<article>
						<h2>Tautybe, pilietybe</h2>
	<?php echo $message."</br>";?>
	<?php //pagrindiniai kliento duomenys
	
	$query = "SELECT *";
	$query .= " FROM `user`";
	$query .= " WHERE `user`.userid =";
	$query .= "'".$_GET['userid']."'";
	
	//echo $query."</br>";
	$result_set = mysql_query($query, $connection);

	$subject = mysql_fetch_array($result_set);
	//print_r ($subject) ;
	
	//echo "Vardas: ";
	echo $subject['vardas'];
	echo ' ';
	
	// echo "Pavarde: ";
	echo $subject['pavarde'];
	echo ' ';	
	
	//echo "Bylos Nr.: ";
	echo $subject['bylosnr'];
	echo '</br>';
	$tau_dabar = $subject['tautybeid'];
	$pil_dabar = $subject['pilietybeid'];
	
?>
    <?php //rodom pagrindine foto jeigu yra
	if ($pagridine_yra == 1){ 
		echo "</br> <img src=\"";
		echo $foto_location;
		echo "\" width=\"150\">";
	};
?> 
   
<form action="tautybe.php?userid=<?php echo ($_GET['userid']);if (($_GET['new'])==1){echo "&new=1";};?>" method="post" name="submit">
  
  </br>
  
  Tautybe: <select name="tautybe" size="1">
			<?php 		$query = "SELECT * 
						FROM `tautybe` 
						ORDER BY tautybeid ASC";
						$tautybe_set = mysql_query($query, $connection);
						confirm_query($tautybe_set);
						while ($tautybe = mysql_fetch_array($tautybe_set)) {
							echo "<option value=\"". $tautybe["tautybeid"] . "\"";
							if ($tautybe["tautybeid"] == $tau_dabar){
							echo " selected";};
							echo ">" . $tautybe["tautybe"] . "</option>";
						};

			?> <option value="0">Kita</option>
			</select>

  Pilietybe: <select name="pilietybe" size="1">
			<?php 		$query = "SELECT * 
						FROM `pilietybe` 
						ORDER BY PilietybeID ASC";
						$pilietybe_set = mysql_query($query, $connection);
						confirm_query($pilietybe_set);
						while ($pilietybe = mysql_fetch_array($pilietybe_set)) {
							echo "<option value=\"". $pilietybe["PilietybeID"] . "\"";
							if ($pilietybe["PilietybeID"] == $pil_dabar){
							echo " selected";};
							echo ">" . $pilietybe["Pilietybe"] . "</option>";
						};

			?> <option value="0">Kita</option>
			</select>			

</br>
<input name="Submit" type="submit" value="<?php if (($_GET['new'])==1) {echo"Toliau";}else{echo"Redaguoti";}; ?>" />
</form>


			</article>
            
<?php require("includes/footer.php"); ?>
